package com.kikidao.app.testclasses.useraccounts;

import com.datalayer.annotations.*;
import com.datalayer.utils.AssociationType;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 7/23/12
 * Time: 2:39 PM
 */
@SuppressWarnings("UnusedDeclaration")
@Entity(tableName = "USERS")
public class User {
    private int id, age;
    Account accountType;
    private String name, password;

    public User() {
    }

    public User(Account accountType, int id, String name, String password, int age) {
        this.accountType = accountType;
        this.id = id;
        this.name = name;
        this.password = password;
        this.age = age;
    }


    @Direction("get")
    @Association(type = AssociationType.ONE2MANY, joins = {
            @Join(fieldName = "accountType", insideName = "ACCOUNT_TYPE", foreignName = "id")
    })
    public Account getAccountType() {
        return accountType;
    }

    @Direction("set")
    @Association(type = AssociationType.ONE2MANY, joins = {
            @Join(fieldName = "accountType", insideName = "ACCOUNT_TYPE", foreignName = "id")
    })
    public void setAccountType(Account accountType) {
        this.accountType = accountType;
    }

    @Direction("get")
    @Constraint(constraintName = "primary key")
    @Attribute(fieldName = "id", attributeName = "USER_ID", type = "int")
    public int getId() {
        return id;
    }

    @Direction("set")
    @Constraint(constraintName = "primary key")
    @Attribute(fieldName = "id", attributeName = "USER_ID", type = "int")
    public void setId(int id) {
        this.id = id;
    }

    @Direction("get")
    @Attribute(fieldName = "age", attributeName = "USER_AGE", type = "int")
    public int getAge() {
        return age;
    }

    @Direction("set")
    @Attribute(fieldName = "age", attributeName = "USER_AGE", type = "int")
    public void setAge(int age) {
        this.age = age;
    }

    @Direction("get")
    @Constraint(constraintName = "unique")
    @Attribute(fieldName = "name", attributeName = "USERNAME", type = "varchar(35)")
    public String getName() {
        return name;
    }

    @Direction("set")
    @Attribute(fieldName = "name", attributeName = "USERNAME", type = "varchar(35)")
    public void setName(String name) {
        this.name = name;
    }

    @Direction("get")
    @Attribute(fieldName = "password", attributeName = "PASSWORD", type = "varchar(35)")
    public String getPassword() {
        return password;
    }

    @Direction("set")
    @Attribute(fieldName = "password", attributeName = "PASSWORD", type = "varchar(35)")
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return age == user.age && id == user.id && !(name != null ? !name.equals(user.name) : user.name != null) && !(password != null ? !password.equals(user.password) : user.password != null);

    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + age;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "User{" +
                "age=" + age +
                ", id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

